;!function (win) {
    "use strict";
    var doc = document
        , Hadmin = function () {
        this.v = '2.2'; //版本号
    }

    Hadmin.prototype.http = function (url, param = {}, method = 'POST', header = {}) {
        let index = layer.msg('请求中...', {icon: 16, shade: 0.5, time: 500000})
        return new Promise((resolve, reject) => {
            axios({
                method: method,
                url: url,
                data: param,
                headers: header,
            }).then(function (response) {
                let result = response.data;
                layer.close(index)
                if (result.code == 1) {
                    resolve(result)
                } else {
                    return layer.msg(result.msg, {icon: 5, shade: 0.5})
                }


            }).catch(function (error) {
                layer.close(index)
                return layer.msg("系统内部异常", {icon: 5, shade: 0.5})
            });
        });
    };
    Hadmin.prototype.father_reload = function() {
        parent.location.reload();
    };
    /**
     * [open 打开弹出层]
     * @param  {[type]}  title [弹出层标题]
     * @param  {[type]}  url   [弹出层地址]
     * @param  {[type]}  w     [宽]
     * @param  {[type]}  h     [高]
     * @param  {Boolean} full  [全屏]
     * @return {[type]}        [description]
     */
    Hadmin.prototype.add = function (title, url, w, h, full) {
        if (title == null || title == '') {
            title = false;
        }
        ;
        if (url == null || url == '') {
            var url = "/404.html";
        }
        ;
        if (w == null || w == '') {
            var w = ($(window).width() * 0.9);
        }
        ;
        if (h == null || h == '') {
            var h = ($(window).height() - 50);
        }
        ;
        let index = layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            title: title,
            content: url,
            zIndex:99999999999
        });
        if (full) {
            layer.full(index);
        }
    }
    Hadmin.prototype.open_img = function (img_src = '') {
        let index = layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: img_src
        })
    }


    win.hadmin = new Hadmin();
}(window);